#ifndef __LINKTREE_H_
#define __LINKTREE_H_

#include <string>
#include "DynamicArray.h"

using ElementType = std::string;

class TreeNode
{
public:
    TreeNode(const ElementType& element);
    //将节点绑定为另一个节点的孩子
    void Connect(TreeNode* parent);
    //解绑
    void DisConnect(TreeNode* parent);


    static TreeNode* FindNode(TreeNode* node,const ElementType& element);
    static void FindNode(TreeNode* node,const ElementType& element,DARRAY::DynamicArray& a);
    static void FreeNode(TreeNode* node);
    static int GetNodeHeight(TreeNode* node);
   
    void show(TreeNode* node,int depth);

    TreeNode* GetParent();
    std::string& GetData();
    void SetData(const ElementType& element);
private:

    ElementType data; //数据域
    TreeNode* parent; //双亲指针
    TreeNode* FirstChild;  //孩子指针
    TreeNode* nextSbling; //下一个兄弟指针
};


class LinkTree
{
public:
    LinkTree();
    LinkTree(const ElementType& element);
    ~LinkTree();
    TreeNode* GetRoot();
    void show();
    DARRAY::DynamicArray FindByElement(const ElementType& element);
    int GetTreeHeight();
    std::string GetNodePath(TreeNode* node);
private:
    TreeNode *root;//根节点
};






#endif